<?php $route = strtolower($this->controller->route); ?>
<ul>
    <li><a<?php if ($route == 'site/index') echo ' class="active"'; ?> href="<?php echo Yii::app()->createUrl('/site/index',array('locale'=>Yii::app()->language)); ?>"><?php echo Yii::t('site/general','Home'); ?></a></li>
    <?php
    // get article background (first article in category about-us)
    $background_article = LanguageArticle::model()->with('article')->find(
        array(
            'order'=>'article.id ASC',
            'condition'=>'locale=:locale AND article.category_id=:catId AND article.status=:status',
            'params' => array(
                ':locale' => Yii::app()->language,
                ':catId' => ArticleSettings::ABOUT_US_CATEGORY_ID,
                ':status' => Article::STATUS_ACTIVE,
            )
        )
    );
    ?>
    <?php if (!is_null($background_article)) : ?>
        <li>
            <?php
            $htmlOpts = array();
            if ($route == 'article/default/view' && $this->controller->get('cat_id',0) == ArticleSettings::ABOUT_US_CATEGORY_ID)
                $htmlOpts['class'] = 'active';
            echo CHtml::link(Yii::t('site/general','About Us'),Yii::app()->createUrl('/Article/default/view',array('cat_id'=>$background_article->article->category_id,'locale'=>$background_article->locale,'id'=>$background_article->article_id,'alias'=>$background_article->alias)),$htmlOpts);    
            ?>
        </li>
    <?php endif; ?>
    <li>
        <?php
        $htmlOpts = array();
        if (in_array($route,array('product/default/listbycategory','product/default/view','product/default/index')))
            $htmlOpts['class'] = 'active';
        echo CHtml::link(Yii::t('site/general','Products'),Yii::app()->createUrl('/Product/default/index',array('locale'=>Yii::app()->language)),$htmlOpts);
        ?>
    </li>
    <?php
    // get category about service
    $service_cat = LanguageCategory::model()->with('category')->find(
        't.category_id=:catId AND locale=:locale AND category.is_active = 1',
        array(
            ':catId' => ArticleSettings::SERVICES_CATEGORY_ID,
            ':locale' => Yii::app()->language,
        )
    );
    if (!is_null($service_cat)) :
    ?>
        <li>
            <?php
            $htmlOpts = array();
            $selectedCatId = 0;
            if ($route == 'article/default/listbycategory')
                $selectedCatId = $this->controller->get('id',0);
            elseif ($route == 'article/default/view')
                $selectedCatId = $this->controller->get('cat_id',0);
            if (in_array($route,array('article/default/listbycategory','article/default/view')) && $selectedCatId == $service_cat->category_id)
                $htmlOpts['class'] = 'active';
            echo CHtml::link($service_cat->title,Yii::app()->createUrl('/Article/default/listByCategory',array('locale'=>$service_cat->locale,'id'=>$service_cat->category_id,'alias'=>$service_cat->alias)),$htmlOpts);
            ?>
        </li>
    <?php endif; ?>
    <?php
    // get category about news
    $news_cat = LanguageCategory::model()->with('category')->find(
        't.category_id=:catId AND locale=:locale AND category.is_active = 1',
        array(
            ':catId' => ArticleSettings::NEWS_CATEGORY_ID,
            ':locale' => Yii::app()->language,
        )
    );
    if (!is_null($news_cat)) :
    ?>
        <li>
            <?php
            $htmlOpts = array();
            $selectedCatId = 0;
            if ($route == 'article/default/listbycategory')
                $selectedCatId = $this->controller->get('id',0);
            elseif ($route == 'article/default/view')
                $selectedCatId = $this->controller->get('cat_id',0);
            $parentCatIds = FSM::run('Core.Category.getParentIds',array('id'=>$selectedCatId))->ids;
            if (in_array($route,array('article/default/listbycategory','article/default/view')) && in_array($news_cat->category_id,$parentCatIds))
                $htmlOpts['class'] = 'active';
            echo CHtml::link($news_cat->title,Yii::app()->createUrl('/Article/default/listByCategory',array('locale'=>$news_cat->locale,'id'=>$news_cat->category_id,'alias'=>$news_cat->alias)),$htmlOpts);
            ?>
        </li>
    <?php endif; ?>
    <li><a<?php if ($route=='partner/default/index') echo ' class="active"'; ?> href="<?php echo Yii::app()->createUrl('/Partner/default/index',array('locale'=>Yii::app()->language)); ?>"><?php echo Yii::t('site/general','Partners'); ?></a></li>
    <?php
    // get category about career
    $career_cat = LanguageCategory::model()->with('category')->find(
        't.category_id=:catId AND locale=:locale AND category.is_active = 1',
        array(
            ':catId' => ArticleSettings::RECRUITMENT_CATEGORY_ID,
            ':locale' => Yii::app()->language,
        )
    );
    if (!is_null($career_cat)) :
    ?>
        <li>
            <?php
            $htmlOpts = array();
            $selectedCatId = 0;
            if ($route == 'article/default/listbycategory')
                $selectedCatId = $this->controller->get('id',0);
            elseif ($route == 'article/default/view')
                $selectedCatId = $this->controller->get('cat_id',0);
            if (in_array($route,array('article/default/listbycategory','article/default/view')) && $selectedCatId == $career_cat->category_id)
                $htmlOpts['class'] = 'active';
            echo CHtml::link(Yii::t('site/general','Careers'),Yii::app()->createUrl('/Article/default/listByCategory',array('locale'=>$career_cat->locale,'id'=>$career_cat->category_id,'alias'=>$career_cat->alias)),$htmlOpts);
            ?>
        </li>
    <?php endif; ?>
    <?php
    // get root category about document
    $root_doc_cat = LanguageCategory::model()->with('category')->find(
        't.category_id=:catId AND locale=:locale AND category.is_active = 1',
        array(
            ':catId' => SiteSettings::ROOT_DOCUMENT_CATEGORY_ID,
            ':locale' => Yii::app()->language,
        )
    );
    if (!is_null($root_doc_cat)) :
    ?>
        <li>
            <?php
            $htmlOpts = array();
            $selectedCatId = 0;
            if ($route == 'site/documents/listbycategory')
                $selectedCatId = $this->controller->get('id',0);
            elseif ($route == 'site/documents/view')
                $selectedCatId = $this->controller->get('cat_id',0);
            $parentCatIds = FSM::run('Core.Category.getParentIds',array('id'=>$selectedCatId))->ids;
            if (in_array($route,array('site/documents/listbycategory','site/documents/view')) && in_array($root_doc_cat->category_id,$parentCatIds))
                $htmlOpts['class'] = 'active';
            echo CHtml::link($root_doc_cat->title,Yii::app()->createUrl('/Site/documents/listByCategory',array('locale'=>$root_doc_cat->locale,'id'=>$root_doc_cat->category_id,'alias'=>$root_doc_cat->alias)),$htmlOpts);
            ?>
        </li>
    <?php endif; ?>
    <li><a<?php if ($route == 'site/contact') echo ' class="active"'; ?> href="<?php echo Yii::app()->createUrl('/site/contact',array('locale'=>Yii::app()->language)); ?>"><?php echo Yii::t('site/general','Contact'); ?></a></li>
</ul>